package net.aiion.weave.impl.conversions;

import net.aiion.weave.spi.conversions.ConverterContext;
import net.aiion.weave.spi.conversions.annotations.Converts;
import net.aiion.weave.spi.naming.annotations.DynamicScoped;
import net.aiion.weave.spi.naming.annotations.Named;

@DynamicScoped
@Named
public class PrimitivesConverter
{
    public PrimitivesConverter() {
    }

    @Converts(String.class)
    public boolean convertStringToPrimitiveBoolean(final ConverterContext aConverterContext) {
        return Boolean.parseBoolean((String) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public Boolean convertStringToBoxedBoolean(final ConverterContext aConverterContext) {
        return convertStringToPrimitiveBoolean(aConverterContext);
    }

    @Converts(boolean.class)
    public String convertPrimitiveBooleanToString(final ConverterContext aConverterContext) {
        return Boolean.toString((boolean) aConverterContext.getSourceValue());
    }

    @Converts(Boolean.class)
    public String convertBoxedBooleanToString(final ConverterContext aConverterContext) {
        return Boolean.toString((Boolean) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public byte convertStringToPrimitiveByte(final ConverterContext aConverterContext) {
        return Byte.parseByte((String) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public Byte convertStringToBoxedByte(final ConverterContext aConverterContext) {
        return convertStringToPrimitiveByte(aConverterContext);
    }

    @Converts(byte.class)
    public String convertPrimitiveByteToString(final ConverterContext aConverterContext) {
        return Byte.toString((byte) aConverterContext.getSourceValue());
    }

    @Converts(Byte.class)
    public String convertBoxedByteToString(final ConverterContext aConverterContext) {
        return Byte.toString((Byte) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public char convertStringToPrimitiveChar(final ConverterContext aConverterContext) {
        return ((String) aConverterContext.getSourceValue()).charAt(0);
    }

    @Converts(String.class)
    public Character convertStringToBoxedChar(final ConverterContext aConverterContext) {
        return convertStringToPrimitiveChar(aConverterContext);
    }

    @Converts(char.class)
    public String convertPrimitiveCharToString(final ConverterContext aConverterContext) {
        return Character.toString((char) aConverterContext.getSourceValue());
    }

    @Converts(Character.class)
    public String convertBoxedCharToString(final ConverterContext aConverterContext) {
        return Character.toString((Character) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public short convertStringToPrimitiveShort(final ConverterContext aConverterContext) {
        return Short.parseShort((String) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public Short convertStringToBoxedShort(final ConverterContext aConverterContext) {
        return convertStringToPrimitiveShort(aConverterContext);
    }

    @Converts(short.class)
    public String convertPrimitiveShortToString(final ConverterContext aConverterContext) {
        return Short.toString((short) aConverterContext.getSourceValue());
    }

    @Converts(Short.class)
    public String convertBoxedShortToString(final ConverterContext aConverterContext) {
        return Short.toString((Short) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public int convertStringToPrimitiveInt(final ConverterContext aConverterContext) {
        return Integer.parseInt((String) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public Integer convertStringToBoxedInt(final ConverterContext aConverterContext) {
        return convertStringToPrimitiveInt(aConverterContext);
    }

    @Converts(int.class)
    public String convertPrimitiveIntToString(final ConverterContext aConverterContext) {
        return Integer.toString((int) aConverterContext.getSourceValue());
    }

    @Converts(Integer.class)
    public String convertBoxedIntToString(final ConverterContext aConverterContext) {
        return Integer.toString((Integer) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public long convertStringToPrimitiveLong(final ConverterContext aConverterContext) {
        return Long.parseLong((String) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public Long convertStringToBoxedLong(final ConverterContext aConverterContext) {
        return convertStringToPrimitiveLong(aConverterContext);
    }

    @Converts(long.class)
    public String convertPrimitiveLongToString(final ConverterContext aConverterContext) {
        return Long.toString((long) aConverterContext.getSourceValue());
    }

    @Converts(Long.class)
    public String convertBoxedLongToString(final ConverterContext aConverterContext) {
        return Long.toString((Long) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public float convertStringToPrimitiveFloat(final ConverterContext aConverterContext) {
        return Float.parseFloat((String) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public Float convertStringToBoxedFloat(final ConverterContext aConverterContext) {
        return convertStringToPrimitiveFloat(aConverterContext);
    }

    @Converts(float.class)
    public String convertPrimitiveFloatToString(final ConverterContext aConverterContext) {
        return Float.toString((float) aConverterContext.getSourceValue());
    }

    @Converts(Float.class)
    public String convertBoxedFloatToString(final ConverterContext aConverterContext) {
        return Float.toString((Float) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public double convertStringToPrimitiveDouble(final ConverterContext aConverterContext) {
        return Double.parseDouble((String) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public Double convertStringToBoxedDouble(final ConverterContext aConverterContext) {
        return convertStringToPrimitiveDouble(aConverterContext);
    }

    @Converts(double.class)
    public String convertPrimitiveDoubleToString(final ConverterContext aConverterContext) {
        return Double.toString((double) aConverterContext.getSourceValue());
    }

    @Converts(Double.class)
    public String convertBoxedDoubleToString(final ConverterContext aConverterContext) {
        return Double.toString((Double) aConverterContext.getSourceValue());
    }

    @Converts(String.class)
    public String convertStringToString(final ConverterContext aConverterContext) {
        return (String) aConverterContext.getSourceValue();
    }
}
